#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
struct record
{
	int A;
	int B;
	int C;
};
struct ball
{
	int D;
	int E;
};
struct date
{
	char name[50];
	struct record F;
	struct ball G;
	int score;
	int H;
};
void Swap(struct date* a, struct date* b)
{
	struct date c;
	c = *a;
	*a = *b;
	*b = c;
}
int my_cmp(struct date a, struct date b)
{
	if (a.score > b.score)
	{
		return 1;
	}
	else if (a.score == b.score)
	{
		if (a.H > b.H)
		{
			return 1;
		}
		else
		{
			return 0;
		}
	}
	else
	{
		return 0;
	}
}
int main()
{
	struct date a[4];
	int i = 0;
	for (i = 0;i < 4;i++)
	{
		scanf("%s ", a[i].name);
		scanf("%d/%d/%d ", &a[i].F.A, &a[i].F.B, &a[i].F.C);
		scanf("%d/%d", &a[i].G.D, &a[i].G.E);
		a[i].score = (a[i].F.A) * 3 + (a[i].F.B);
		a[i].H = (a[i].G.D) - (a[i].G.E);
	}
	for (i = 0;i < 3;i++)
	{
		int j = 0;
		for (j = 0;j < 3 - i;j++)
		{
			if (my_cmp(a[j], a[j + 1]) > 0)
			{
				Swap(&a[j], &a[j + 1]);
			}
		}
	}
	printf("%s %s", a[3].name, a[2].name);
	return 0;
}